<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <base href="<?= base_url() ?>"/>
        <title>乐天！ &raquo; 首页</title>
        <meta name="generator" content="Order 1.0" /> 
        <link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
        <link rel="stylesheet" href="css/style.css" type="text/css" />
        <link rel="stylesheet" href="css/uploadify.css" type="text/css" />
        <link rel="stylesheet" href="jquery-ui/css/ui-lightness/jquery-ui-1.9.0.custom.min.css" />
        <script src="jquery-ui/js/jquery-1.8.2.js" type="text/javascript" charset="utf-8"></script>
        <script src="jquery-ui/js/jquery-ui-1.9.0.custom.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.uploadify.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
        <script>
            $(function() {              
                var is_modifying = false;
                var modifying_index = -1;
                var img_path ="/uploads/default.png";
                $("input[name='all_kinds']").val(0);
                $("#img_box").attr("src",img_path); 
                $("#commodity_img").val(img_path);
                $('#file_upload').uploadify({
                    'swf'      : 'css/uploadify.swf',
                    'uploader' : 'css/uploadify.php',
                    'buttonText': '选择图片',
                    'fileTypeExts': '*.gif;*.jpg;*.jpeg;*.png', 
                    onUploadSuccess  : function(file, data, response)
                    {                 
                        $("#img_box").attr("src",data);                      
                        $("#commodity_img").val(data);
                    }
                });

                $("input[name*='Time']").datepicker({dateFormat : 'yy-mm-dd'});

                //根据str2载入commodity数据
                function load_input(str2){
                    $("#submit_form input[type=hidden]").each(function(){
                        var content= this.name;
                        if(content.indexOf(str2)>0)
                        {
                            if(content.indexOf("commodityNumber")>=0)
                                $("#commodity_number").val($(this).val());
                            if(content.indexOf("commodityNumber")>=0)
                                $("#commodity_colorAndSize").val($(this).val());
                            if(content.indexOf("img_name")>=0){
                                $("#img_box").attr("src",$(this).val());  
                                $("#commodity_img").val($(this).val());
                            }
                              
                            if(content.indexOf("link")>=0)
                                $("#commodity_link").val($(this).val());
                            if(content.indexOf("unitPrice")>=0)
                                $("#commodity_unitPrice").val($(this).val());
                            if(content.indexOf("colorAndSize")>=0)
                                $('#commodity_colorAndSize').val($(this).val());
                            if(content.indexOf("amount")>=0)
                                $("#commodity_amount").val($(this).val());
                           // if(content.indexOf("freight")>=0)
                                //$("#commodity_freight").val($(this).val());
                        }
                    })
                }
                //删除包含有str2字符串的 input
                var delete_input = function(str2){
                    $("#submit_form input[type=hidden]").each(function(){
                        var content= this.name;
                        if(content.indexOf(str2)>0)
                        {
                            $(this).remove();
                        }
                    })
                }
                
                function save_input(index){                
                    //保存修改
                    $("#submit_form input[type=hidden]").each(function(){
                        var content= this.name;
                        if(content.indexOf(index)>0)
                        {
                            if(content.indexOf("commodityNumber")>=0)
                                $(this).val($("#commodity_number").val());
                            if(content.indexOf("commodityNumber")>=0)
                                $(this).val( $("#commodity_colorAndSize").val());
                            if(content.indexOf("img_name")>=0){
                                $(this).val($("#img_box").attr("src"));  
                                $(this).val($("#commodity_img").val());
                            }
                              
                            if(content.indexOf("link")>=0)
                                $(this).val($("#commodity_link").val());
                            if(content.indexOf("unitPrice")>=0)
                                $(this).val($("#commodity_unitPrice").val());
                            if(content.indexOf("colorAndSize")>=0)
                                $(this).val( $('#commodity_colorAndSize').val());
                            if(content.indexOf("amount")>=0)
                                $(this).val( $("#commodity_amount").val());
                          //  if(content.indexOf("freight")>=0)
                               // $(this).val($("#commodity_freight").val());
                        }
                    });
                    
                    $("#commodity_table tr td:last-child").each(function(){
                        if(this.innerHTML==index)
                        {
                            $(this).parent()[0].cells[0].innerHTML=$("#commodity_number").val();
                            $(this).parent()[0].cells[1].innerHTML="<img src='"+$("#commodity_img").val()+"' width='150px' height='150px' />";
                            $(this).parent()[0].cells[2].innerHTML="<a href='"+$("#commodity_link").val()+"' target='_blank' >"+$("#commodity_link").val()+"</a>";
                            $(this).parent()[0].cells[3].innerHTML=$("#commodity_colorAndSize").val();
                            $(this).parent()[0].cells[4].innerHTML=$("#commodity_unitPrice").val();
                            $(this).parent()[0].cells[5].innerHTML=$("#commodity_amount").val();
                         //   $(this).parent()[0].cells[6].innerHTML=$("#commodity_freight").val();
                        }
                    })
                    
                    $("#commodity_form").hide();
                    $("#bgDiv").hide();    
                    $("#commodity_comfirm").unbind("click", save_input);
                    //表示这是新增的commodity
                }
                //确认添加or修改商品处理函数  
            
                var add_input = function()
                { 
                    var pre  = $("input[name='all_kinds']").val();
                    //内容加入商品表单
                    $("#commodity_table").append("<tr></tr>"); 
                    $("#commodity_table tr:last").append("<td>"+$("#commodity_number").val()+"</td>");
                    $img_info = "<div style='border:1px solid #ffecf1;padding:3px;background-color:#efefef'><img src='"+$("#commodity_img").val()+"' width='150px' height='150px' /></div>";
                    $("#commodity_table tr:last").append("<td>"+$img_info+"</td>");
                    $link_info="<a href='"+$("#commodity_link").val()+"' target='_blank' >"+$("#commodity_link").val()+"</a>";
                    $("#commodity_table tr:last").append("<td>" +$link_info+"</td>");
                    $("#commodity_table tr:last").append("<td>"+$("#commodity_colorAndSize").val()+"</td>");
                    $("#commodity_table tr:last").append("<td>"+$("#commodity_unitPrice").val()+"</td>");
                    $("#commodity_table tr:last").append("<td>"+$("#commodity_amount").val()+"</td>");
                   // $("#commodity_table tr:last").append("<td>"+$("#commodity_freight").val()+"</td>");
                    $("#commodity_table tr:last").append("<td><a href='#' class='link_mod'></a>"+"<a href='#' class='link_del'></a></td>");
                    $("#commodity_table tr:last").append("<td style='display:none'>"+pre+"</td>");

                   

                    $("#submit_form").append("<input type='hidden' name='commodityNumber["+pre+"]'"+ "value='"+$('#commodity_number').val()+"' />");
                    $("#submit_form").append("<input type='hidden' name='img_name["+pre+"]'"+ "value='"+$('#commodity_img').val()+"' />");
              
                    $("#submit_form").append("<input type='hidden' name='link["+pre+"]'"+ "value='"+$('#commodity_link').val()+"' />");
                    $("#submit_form").append("<input type='hidden' name='colorAndSize["+pre+"]'"+ "value='"+$('#commodity_colorAndSize').val()+"' />");
                   // $("#submit_form").append("<input type='hidden' name='freight["+pre+"]'"+ "value='"+$('#commodity_freight').val()+"' />");
               
                    $("#submit_form").append("<input type='hidden' name='unitPrice["+pre+"]'"+ "value='"+$('#commodity_unitPrice').val()+"' />");
                    $("#submit_form").append("<input type='hidden' name='amount["+pre+"]'"+ "value='"+$('#commodity_amount').val()+"' />");
                    
                    //增加商品的数量
                  
                    pre++;   
                    $("input[name='all_kinds']").val(pre);
                    $("#commodity_form").hide();
                    $("#bgDiv").hide();                 
                   
                    //给最后一个绑定
                    $(".link_mod:last").click(function(){
                        var $target_elment = $(this).parent().next('td');
                        var index =$target_elment.contents().text();
                        $("#commodity_form input[type=text]").val("");
                        load_input(index);
                        var win_w = $('body').width()/2; 
                        var win_h = window.screen.height/2;
                        is_modifying = true;
                        modifying_index = index;
                        $("#commodity_form").show();
                        $("#bgDiv").show();
                        return false;
                    })
                    
                    
                    $(".link_del:last").click(function(){
                        if(confirm("确定删除？"))
                        {
                            var $target_elment = $(this).parent().next('td');
                            var index =$target_elment.contents().text(); 
                            $target_elment.parent().remove();
                            delete_input(index);
                            return false;
                        }
                        return false;
                    })
                    return false;
                }
             
                //添加商品按键
                $("#add_commodity").click(function(){           
                    $("#img_box").attr("src",img_path); 
                    $("#commodity_img").val(img_path);
                    $("#commodity_form input[type=text]").val("");
                    var win_w = $('body').width()/2;
                    var win_h = $('body').height()/2;
                    $("#commodity_form").show();
                    $("#bgDiv").show();
                    return false;
                })

                $(".link_close").click(function(){
                    is_modifying = false;
                    modifying_index = -1;
                    $("#commodity_form input[type=text]").val("");
                    $("#commodity_form").hide();
                    $("#bgDiv").hide();
                    return false;
                });
                $("#commodity_cancle").click(function(){
                    is_modifying = false;
                    modifying_index = -1;
                    $("#commodity_form input[type=text]").val("");
                    $("#commodity_form").hide();
                    $("#bgDiv").hide();
                });
                
                $("#submit_form").validationEngine({
                    onValidationComplete: function(form, status){
                        if(status==true )     
                        {   
                            if($("input[name='all_kinds']").val()==0){
                                alert('请添加商品！'); 
                                return false;
                             }
                              
                            var data = $("#submit_form").serialize();
                            var url=$("#submit_form")[0].action;
                            //$('#showup').slideUp(500);       
                            $.post(url,data,function(response){
                               // alert(response);
                                if(response == "success"){
                                    alert('订单提交成功');
                                    window.location.reload(); 
                                }else{
                                    alert('订单提交失败');
                                }
//                                alert(reponse);
//                                $('#showup').html('订单提交成功');
//                                $('#showup').fadeOut(3000);
                            });
                        } 
                        return false;
                    }
                });
                $("#commodity_form_test").validationEngine({
                    onValidationComplete: function(form, status){
                        if(status==true )     
                        {
                            if(is_modifying) save_input(modifying_index);
                            else  add_input();
                        }
                    } 
                });
            });    
        </script>
        <style>
            .search_bnt {
                height: 32px;
                font-weight:bold;
                font-size:13px;
                width: 100%;
                background: #7FA448;
                margin: 0;
                border: none;
                cursor: pointer;
                color: white;
            }
            .search_bnt:hover{
                background: #8cb352;
            }
            #commodity_form{
                display: none;background:white;width:500px;padding:20px 20px 10px 20px;margin:0px;border: 5px solid #CCC;
                z-index:9999;
                position:absolute;   
                top:0px;
                left:50%;
                margin:-500px 0 0 -250px;
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div id="header">
                <div id="header-inner">
                    <h1><span><a href="#">乐天！</a></span></h1>
                    <h2>订单管理系统</h2>
                    <div class="clear"></div>
                    <ul class="sw_menu">
                        <li><a href=<?php echo site_url('login')?>  >首页</a></li>
                        <li><a href=<?php echo site_url('order')?> class="sw_menu_current" >管理</a></li>
                        <li><a href=# >筛选</a></li>
                        <?php
                        if ($is_admin)
                            echo '<li><a href=' . site_url('admin') . '>后台</a></li>';
                        ?>
                    </ul>
                </div>
            </div>
            <div id="sidebar">
                <div id="sidebar-inner">
                    <ul>
                        <li class="select">>
                            <?php
                            if($ret['p1']){
                                echo  '<a  href='.site_url("order/new_order") .'>新建订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">新建订单</a>';
                            }
                            ?>
                           
                        </li>
                        <li>
                            <?php
                            if($ret['p2']){
                                echo  '<a  href='.site_url("order/wait_for_pay") .'>待付款订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">待付款订单</a>';
                            }
                            ?>
                        </li>
                        <li>
                            <?php
                            if($ret['p3']){
                                echo  '<a  href='.site_url("order/wait_for_buy") .'>待购货订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">待购货订单</a>';
                            }
                            ?>
                        </li>
                        <li>
                            <?php
                            if($ret['p4']){
                                echo  '<a  href='.site_url("order/wait_for_delivery") .'>待发货订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">待发货订单</a>';
                            }
                            ?>
                        </li>
                        <li>
                        <?php
                            if($ret['p5']){
                                echo  '<a  href='.site_url("order/order_allocation") .'>已发货订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">已发货订单</a>';
                            }
                            ?>                    
                        </li>
                        <div class="clear"></div>
                    </ul>
                </div>
            </div>
            
            <div id="bgDiv"></div>
            <div id="content-wrapper">
                <div style=" display: none;line-height:40px;height: 40px;margin-left:250px;color:white; width:200px;font-size:16px;background:#cc6600;text-align: center;" id='showup'>正在提交订单</div>
                <div id="content">
                    <h3 id="comments-title">       <em>订单内容</em>       </h3>
                    <div class="comment-form">
                        <form id ="submit_form" action=<?php echo site_url("order/order_insert"); ?> method="post">
                            订单基本信息
                            <p>
                                <div style="width:300px;float:left;"> 
                                    <input type="text" name="orderTime" class="validate[custom[date],required]" value="" size="30"/>
                                    <span>订单时间 *</span>
                                </div>
                                <input type="text" name="orderNumber" value="" size="30" class="validate[required]"/>
                                <span >订单编号 *</span>
                            </p>
                            <p>
                                <div style="width:300px;float:left">
                                    <select name="paymentMethod" class="validate[required]" style="width:130px; font-family: inherit" >
                                        <option>信用卡</option>  
                                        <option>银行转账</option>  
                                        <option>货到付款</option>
                                        <option>乐天银行</option>
                                        <option>乐天Edy</option>
                                        <option>信用卡NG</option>  
                                    </select>
                                    <span>付账方式 *</span>
                                </div>
                                <input type="text" name="cashEntryTime" class="validate[custom[date]]" value="" size="30"/>
                                <span>入账时间 *</span>
                            </p>
                            <hr/>客户信息
                            <p>
                                <div style="width:300px;float:left">
                                    <input type="text" name="clientName" class="validate[required]" value="" size="30"/>
                                    <span>客户姓名 *</span>
                                </div>
                                <input type="text" name="postcode" value="" class="validate[required]" size="20"/>
                                <span>邮编 *</span>
                            </p>

                            <p>       
                                <div style="width:450px;float:left">
                                    <input type="text" name="clientAddress" class="validate[required]" value="" size="55"/>
                                    <span>客户地址 *</span>
                                </div>
                                <input type="text" name="clientPhone" class="validate[required]" value="" size="15"/>
                                <span>客户电话 *</span>
                            </p>

                            <hr/>
                            <p>商品信息</p>
                            <table id ="commodity_table">
                                <tr>
                                    <th>商品编号</th>
                                    <th  style="width:158px">商品图片</th>
                                    <th>商品链接</th>
                                    <th>颜色/尺码</th>
                                    <th>单价</th>
                                    <th>数量</th>
<!--                                    <th>运费</th>-->
                                    <th style="width:50px;">操作 </th>
                                    <th style="display:none">index</th>        
                                </tr>
                            </table>
                            <input type ="hidden" value="0" name="all_kinds"/>   

                            <a href="" class="link_add" id ="add_commodity" >添加商品</a>
                            <p>       
                                <div style="width:300px;float:left">
                                    <input type="text" name="freight" class="validate[required]" value="" size="25"/>
                                    <span> 运费(JP) *</span>
                                </div>
                                <input type="text" name="total_mount" class="validate[required]" value="" size="25"/>
                                <span> 总价(JP)  *</span>
                            </p>
                            <div style="margin:5px auto;width: 100px">                               
                                <input type="submit" class="search_bnt" name="submit" value="提交订单"/>              
                            </div>
                        </form>
                    </div>       
                    <div style="position:relative">
                        <div id="commodity_form">
                            <form action=<?php echo site_url("welcome/post"); ?> method="post" id="commodity_form_test">
                                <div style="border-bottom: 1px solid #EAEAEA;height: 40px;line-height: 40px;color: #333;font-size: 16px;margin-bottom: 20px;">
                                    <div style="float:left;display:inline;">商品信息</div>
                                    <div> <a style="float:right;line-height:20px;padding:10px;" href="#" class="link_close"></a></div>
                                </div>
                                <div class="clear"></div>
                                <div style="float:left;display:inline;">
                                    <div  style="border: 1px solid #ffecf1; width:200px; height: 200px;padding:5px;margin:10px;background-color:#efefef">
                                        <img id="img_box" src="" alt="" width="200px" height="200px" /> 
                                    </div>
                                    <div style="margin-left:10px">
                                        <div id="queue"></div>
                                        <input id="file_upload" name="file_upload" type="file" multiple="true"/>                           
                                    </div>
                                </div>
                                <div style="float:right;padding: 15px 0px;margin:0px 5px 0px 0px;display:inline">
                                    <div style="margin: 10px 0px;">
                                        <label>商品编号</label>
                                        <input type="text" id="commodity_number" class="validate[required]" value="" size="30" />
                                    </div>              

                                    <input type="hidden"  value="" id="commodity_img"/>
                                    <div style="margin: 10px 0px;">
                                        <label>商品链接</label>
                                        <input type="text"  id="commodity_link" class="validate[custom[url]]" value="" size="30" />
                                    </div>
                                    <div style="margin: 10px 0px;">
                                        <label>颜色/尺码</label>
                                        <input type="text" id="commodity_colorAndSize" class="validate[required]" value="" size="15" />
                                    </div>
                                    <div style="margin: 10px 0px;">
                                        <label>数量</label>
                                        <input type="text" id="commodity_amount" class="validate[custom[integer],required]" value="" size="15" />
                                    </div>
                                    <div style="margin: 10px 0px;">
                                        <label>单价</label>
                                        <input type="text" id="commodity_unitPrice" class="validate[custom[number],required]" value="" size="15" />
                                    </div>
                                    
<!--                                    <div style="margin: 10px 0px;">
                                        <label>运费</label>
                                        <input type="text"  id="commodity_freight" class="validate[custom[number],required]" value="" size="15" />
                                    </div>  -->
                                    <p>
                                        <div style="padding-top: 40px;">
                                            <input type="submit" class="search_bnt" id ="commodity_comfirm" style="width:80px;margin:0 0px" value="确认"/>
                                            <input type="button" class="search_bnt" id ="commodity_cancle" style="width:80px;margin-left:40px"value="取消"/>
                                        </div> 
                                    </p>
                                </div>
                                <div class="clear">

                                </div>
                            </form>   
                        </div>    
                    </div>
                </div>
                <div class="clear"></div>
                <div id="footer">
                    <hr />
                    <ul>
                        <li>
                            Powered by <a href=#>Swan 1.3.0</a>
                        </li>
                    </ul>
                </div>
            </div>
    </body>
</html>